# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=dbus
pkgver=1.14.10
pkgrel=1
pkgdesc="Freedesktop.org message bus system"
url="https://www.freedesktop.org/Software/dbus"
arch="all"
license="AFL-2.1 OR GPL-2.0-or-later"
depends_dev="util-linux-dev"
makedepends="
	$depends_dev
	expat-dev
	glib-dev
	libsm-dev
	libx11-dev
	meson
	xmlto
	"
pkggroups="messagebus"
install="$pkgname.pre-install $pkgname.post-install"
triggers="$pkgname.trigger=/usr/share/dbus-1/system.d"
subpackages="
	$pkgname-dev
	$pkgname-doc
	$pkgname-libs
	$pkgname-x11
	$pkgname-openrc
	$pkgname-daemon-launch-helper:launchhelper
	"
source="https://dbus.freedesktop.org/releases/dbus/dbus-$pkgver.tar.xz
	$pkgname.initd
	$pkgname.confd
	"
options="!check" # fail on 1.14

# secfixes:
#   1.14.4-r0:
#     - CVE-2022-42010
#     - CVE-2022-42011
#     - CVE-2022-42012
#   1.12.18-r0:
#     - CVE-2020-12049
#   1.12.16-r0:
#     - CVE-2019-12749

build() {
	CFLAGS="$CFLAGS -flto=auto" \
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--localstatedir=/var \
		--sysconfdir=/etc \
		--with-system-pid-file=/run/dbus/dbus.pid \
		--enable-checks \
		--disable-assertions
	make
}

check() {
	make check
}

package() {
	make DESTDIR="$pkgdir" install

	install -Dm755 "$srcdir"/dbus.initd "$pkgdir"/etc/init.d/dbus
	install -Dm644 "$srcdir"/dbus.confd "$pkgdir"/etc/conf.d/dbus

	# can't  install tmpfs
	rm -r "$pkgdir"/var/run
}

libs() {
	pkgdesc="D-BUS access libraries"
	replaces="dbus"

	amove usr/lib/lib*.so.*
}

x11() {
	pkgdesc="X11 add-ons for D-BUS"
	depends="dbus=$pkgver-r$pkgrel"

	amove usr/bin/dbus-launch
}

launchhelper() {
	pkgdesc="DBus SUID launch helper for autospawning"
	install_if="$pkgname=$pkgver-r$pkgrel"

	amove usr/libexec/dbus-daemon-launch-helper
}

sha512sums="
775b708326059692937acb69d4ce1a89e69878501166655b5d1b1628ac31b50dd53d979d93c84e57f95e90b15e25aa33893e51a7421d3537e9c2f02b1b91bfae  dbus-1.14.10.tar.xz
b0c17503fd18ae7f9a4df46aaf5811dddb63b9868b47d20fb5b9b49843ee159b1634fb7f27f9f7784bf26f751ab49302ea3053ae5d1acf875a0885286430e653  dbus.initd
ea5df31eab4635da8af241c29878ca59927479f7bef71252416806d1504023da3c951a61bd6150fab0e1dbdde5ccfd91616db6043875b7babdf2bada873450dc  dbus.confd
"
